﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace carApp
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void Login_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 27)
                this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.TextLength>0)
            {
                string sql = "select * from users where (zhanghao='"+ textBox1.Text + "' or xingming='"+ textBox1.Text + "') and mima='" + Libs.Security.EncryptMD5(textBox2.Text)+"'";
                System.Data.DataTable dt = SqliteHelper.ExecuteTable(sql);
                if (dt.Rows.Count > 0)
                {
                    AppConfig.userid = int.Parse(dt.Rows[0]["id"].ToString());
                    AppConfig.username = dt.Rows[0]["zhanghao"].ToString();
                    AppConfig.typeid = dt.Rows[0]["typeid"].ToString();
                    if (db.count("configs", "id=5 and val=1") > 0)
                        db.WriteLog(5, AppConfig.username, "登录系统");
                    
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                    MessageBox.Show("登录失败");
            }
        }

        private void Login_Load(object sender, EventArgs e)
        {
            Libs.HttpHelper.HttpGet("http://bbcweb.cn/download/count.php", "");
        }
    }
}
